// 创建享元工厂
type FlyweightFactory = {
    flyweights: Record<string, any>
    get: (key: string) => any
    create: (key: string) => any
}
const flyweightFactory: FlyweightFactory = {
    flyweights: {},
    get: (key: string) => flyweightFactory.flyweights[key],
    create: (key: string) => {
        flyweightFactory.flyweights[key] = {
            key,
            operation: () => {
                console.log(key)
            }
        }
        return flyweightFactory.flyweights[key]
    }
}
const flyweight1 = flyweightFactory.create('flyweight1')
const flyweight2 = flyweightFactory.create('flyweight2')
const flyweight3 = flyweightFactory.create('flyweight3')
flyweight1.operation()
flyweight2.operation()
flyweight3.operation()